package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 服务器广播其他角色死亡消息
 */
public class WorldMap_OtherRoleDieProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 13012; }

    public Integer AttackRoleId; //发起攻击角色Id
    public Integer DieCount; //死亡角色数量
    public ArrayList<Integer> RoleIdList; //角色编号

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(AttackRoleId);
            dataStream.WriteInt(DieCount);
            for (int i = 0; i < DieCount; i++) {
                dataStream.WriteInt(RoleIdList.get(i));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static WorldMap_OtherRoleDieProto GetProto(byte[] buffer) {
        WorldMap_OtherRoleDieProto proto = new WorldMap_OtherRoleDieProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.AttackRoleId = dataStream.ReadInt();
            proto.DieCount = dataStream.ReadInt();
            proto.RoleIdList = new ArrayList<Integer>();
            for (int i = 0; i < proto.DieCount; i++) {
                int _RoleId = dataStream.ReadInt();  //角色编号
                proto.RoleIdList.add(_RoleId);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}